package top.ijiujiu.exception;

import lombok.Getter;
import org.springframework.http.HttpStatus;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;

/**
 * DefaultException
 *
 * @Author 神秘的黄瓜
 * @Version 1.0
 * @Date 2020-04-01 10:33
 */
@Getter
public class DefaultException extends Exception {

    private final Integer status;

    private final String message;

    public DefaultException(String message) {
        this.status = HttpStatus.INTERNAL_SERVER_ERROR.value();
        this.message = StringUtils.isEmpty(message) ? HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase() : message;
    }

    public DefaultException(HttpStatus status, String message) {
        this.status = ObjectUtils.isEmpty(status) ? HttpStatus.INTERNAL_SERVER_ERROR.value() : status.value();
        this.message = StringUtils.isEmpty(message) ? HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase() : message;
    }
}
